home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue62 / Alfresco / TestAAHpDist.dpr < prev    next >
Encoding:
Text File  |  2000-08-21  |  1.5 KB  |  62 lines

  1. program TestAAHpDist;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   AAHpDist in 'AAHpDist.pas',
  7.   SysUtils;
  8.  
  9. var
  10.   PtrArray : array [0..127] of pointer;
  11.   i        : integer;
  12.   TotalGets: integer;
  13.  
  14. begin
  15.   writeln('Testing AAHpDist...');
  16.   try
  17.  
  18.  
  19.     {at this point the replacement heap manager should be installed}
  20.     Assert(IsMemoryManagerSet, 'Heap manager has not been replaced');
  21.  
  22.     {clear the bins--gets rid of the allocations SysUtils makes}
  23.     FillChar(aaHeapBins, sizeof(aaHeapBins), 0);
  24.  
  25.     writeln('allocate 128 pointers');
  26.     for i := 0 to 127 do
  27.       GetMem(PtrArray[i], Random(512) + 1);
  28.  
  29.     writeln('free every even element');
  30.     for i := 0 to 127 do
  31.       if not Odd(i) then begin
  32.         FreeMem(PtrArray[i]);
  33.         PtrArray[i] := nil;
  34.       end;
  35.  
  36.     writeln('reallocate every odd element');
  37.     for i := 0 to 127 do
  38.       if Odd(i) then
  39.         ReallocMem(PtrArray[i], Random(512) + 1);
  40.  
  41.     writeln('free every odd element');
  42.     for i := 0 to 127 do
  43.       if Odd(i) then begin
  44.         FreeMem(PtrArray[i]);
  45.         PtrArray[i] := nil;
  46.       end;
  47.  
  48.     writeln('making sure there are 192 allocations');
  49.     TotalGets := 0;
  50.     for i := low(aaHeapBins) to high(aaHeapBins) do
  51.       inc(TotalGets, aaHeapBins[i]);
  52.     Assert(TotalGets=192, 'The Total allocations is wrong');
  53.     
  54.     writeln('done');
  55.   except
  56.     on E : Exception do
  57.       writeln(E.Message);
  58.   end;
  59.   write('Press Enter to close...');
  60.   readln;
  61. end.
  62.